package com.hksj.cbm.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hksj.cbm.dto.SpaceModelDTO;
import com.hksj.cbm.entity.SpaceModel;
import com.hksj.cbm.query.SpaceModelQuery;
import com.hksj.cbm.service.SpaceModelService;
import com.hksj.cbm.vo.SpaceModelVO;
import com.hksj.common.config.utils.PageResult;
import com.hksj.common.core.model.Rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zengke
 * @version 1.0
 * @see SpaceModelController
 * @since 2024/7/11 14:57
 */
@Api(tags = "基础模块-空间模型管理")
@RestController
@RequestMapping("/api/spaceModel")
public class SpaceModelController {

    @Autowired
    private SpaceModelService spaceModelService;

    @ApiOperation(value = "创建空间模型")
    @PostMapping("/createSpaceModel")
    public Rest<String> createSpaceModel(@RequestBody SpaceModelDTO spaceModelDTO){
        String result = spaceModelService.createSpaceModel(spaceModelDTO);
        return Rest.ok(result);
    }

    @ApiOperation(value = "更新空间模型")
    @PutMapping("/updateSpaceModel")
    public Rest<String> updateSpaceModel(@RequestBody SpaceModelDTO spaceModelDTO){
        String result = spaceModelService.updateSpaceModel(spaceModelDTO);
        return Rest.ok(result);
    }

    @ApiOperation(value = "删除空间模型")
    @DeleteMapping("/deleteSpaceModel")
    public Rest<String> deleteSpaceModel(Long id){
        String result = spaceModelService.deleteSpaceModel(id);
        return Rest.ok(result);
    }

    @ApiOperation(value = "查询空间模型树")
    @PostMapping("/querySpaceModelTree")
    public Rest<List<SpaceModel>> querySpaceModelTree(@RequestBody SpaceModelDTO spaceModelDTO){
        List<SpaceModel> spaceModelList = spaceModelService.querySpaceModelTree(spaceModelDTO);
        return Rest.ok(spaceModelList);
    }

    @ApiOperation(value = "分页查询空间模型列表")
    @PostMapping("/querySpaceModelListByPaging")
    public Rest<PageResult<SpaceModelVO>> querySpaceModelListByPaging(@RequestBody SpaceModelQuery spaceModelQuery){
        Page<SpaceModelVO> page = spaceModelService.querySpaceModelListByPaging(spaceModelQuery);

        //将分页结果进行封装
        PageResult<SpaceModelVO> result = PageResult.restPage(page);

        //将封装结果返回
        return Rest.ok(result);
    }

    @ApiOperation(value = "查询所有空间模型列表")
    @PostMapping("/querySpaceModelList")
    public Rest<List<SpaceModel>> querySpaceModelList(@RequestBody SpaceModelQuery spaceModelQuery){
        List<SpaceModel> result = spaceModelService.list();
        return Rest.ok(result);
    }

    @ApiOperation(value = "父查子")
    @GetMapping("/querySpaceModelChildren")
    public Rest<List<SpaceModelVO>> querySpaceModelChildren(Long id){
        List<SpaceModelVO> children = spaceModelService.querySpaceModelChildren(id);
        return Rest.ok(children);
    }

    @ApiOperation(value = "子查父")
    @GetMapping("/querySpaceModelParent")
    public Rest<List<SpaceModelVO>> querySpaceModelParent(Long id){
        List<SpaceModelVO> parent = spaceModelService.querySpaceModelParent(id);
        return Rest.ok(parent);
    }

}
